<template>
    <div class="container2">
      <Nav></Nav>
      <div class="swiper-container">
        <div class="swiper-wrapper">
          <div class="swiper-slide" v-for="(item,index) in swiperimg" :key="index">
            <img :src="item" alt="">
          </div>
        </div>

        <!-- Add Pagination -->
        <div class="swiper-pagination"></div>
      </div>
      <div class="con-d1">
        <span>资讯动态</span>
        <span @click="more()">更多资讯 <img :src="'./static/lyl/youjian.png'" alt=""></span>
      </div>
      <ul class="ulone">
        <li @click="deta(item)" v-for="(item,index) in datatx" :key="index">
          <div class="li-left">
            <p>{{item.post_title}}</p>
            <div class="li-footer">
              <span>{{item.user_login}}</span>
              <span>{{item.post_date}}</span>
            </div>
          </div>
          <img :src="item.smeta" alt="">
        </li>
      </ul>
      <p class="p1">舞会活动</p>
      <ul class="ultwo">
        <li v-for="(item,index) in dataty" :key="index" @click="actdet(item)">
          <div class="li-top">
            <img :src="item.main_pic" alt="">
            <span>{{item.apply}}</span>
            <span v-if="item.is_rec==0?false:true">推荐</span>
          </div>
          <p>{{item.title}}</p>
        </li>
      </ul>


      <Footer></Footer>
    </div>
</template>

<script>
  import Swiper from 'swiper'
  import Nav from '../../com/Nav'
  import Footer from '../../com/Footer'
  import * as home from "../../../api/home.js";
    export default {
      name: "Home",
      data(){
        return {
          datatx:[],
          dataty:[],
          swiperimg:[]
        }
      },
      components:{
        Nav,
        Footer
      },
      beforeMount(){
        let parmes = {type:1};
        home.bannerList(parmes).then(res=>{
          this.swiperimg = res.data;
          this.$nextTick(() => {  // 下一个UI帧再初始化swiper
            var swiper = new Swiper('.swiper-container', {
              autoplay:true,
              loop : true,
              pagination: {
                el: '.swiper-pagination',
              },
            });
          })
        });

        home.postsList(parmes).then(res=>{
          this.datatx = res.data;
        });

        home.activeList(parmes).then(res=>{
          this.dataty = res.data;
        })
      },
      // mounted(){
      //   // //首页返回键处理
      //   // //处理逻辑：1秒内，连续两次按返回键，则退出应用；
      //   var first = null;
      //   mui.back = function() {
      //     //首次按键，提示  再按一次退出应用
      //     if (!first) {
      //       first = new Date().getTime();//记录第一次按下回退键的时间
      //       mui.toast('再按一次退出应用');//给出提示
      //       history.go(-1)//回退到上一页面
      //       setTimeout(function() {//1s中后清除
      //         first = null;
      //       }, 1000);
      //     } else {
      //       if (new Date().getTime() - first < 1000) {//如果两次按下的时间小于1s，
      //         plus.runtime.quit();//那么就退出app
      //
      //       } } };
      // },
      methods:{
        more(){
          this.$router.push({ path: "/morenews" });
        },
        deta(item){
          this.$router.push({path:'/detail/'+item.id});
        },
        actdet(item){
          this.$router.push({path:'/active2/0/'+item.id});
        }
      }
    }
</script>

<style>
  .container2{
    padding-bottom: 158px;
  }
  .swiper-container {
    width: 100%;
  }
  .swiper-slide {
    text-align: center;
    font-size: 18px;
    background: #fff;

    /* Center slide text vertically */
    display: -webkit-box;
    display: -ms-flexbox;
    display: -webkit-flex;
    display: flex;
    -webkit-box-pack: center;
    -ms-flex-pack: center;
    -webkit-justify-content: center;
    justify-content: center;
    -webkit-box-align: center;
    -ms-flex-align: center;
    -webkit-align-items: center;
    align-items: center;
  }
  .swiper-slide img{
    width: 100%;
    height: 400px;
  }
  .swiper-container-horizontal>.swiper-pagination span.swiper-pagination-bullet{
    width: 20px;
    height: 20px;
    border-radius: 100%;
    background: #fff;
    opacity: 1;
    filter:alpha(opacity=100);
    margin: 0 16px;
  }
  .swiper-container-horizontal>.swiper-pagination span.swiper-pagination-bullet-active{
    background: #a966ec;
  }
  .con-d1{
    display: flex;
    justify-content: space-between;
    padding: 20px 40px;
  }
  .con-d1 span:nth-child(1){
    font-size: 32px;
  }
  .con-d1 span:nth-child(2){
    font-size: 26px;
  }
  .con-d1 span:nth-child(2) img{
    width: 11px;
  }
  .ulone li{
    display: flex;
    justify-content: space-between;
    padding: 0 40px;
    margin-bottom: 30px;
  }
  .ulone li .li-left{
    width: 390px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

  }
  .ulone li .li-left p{
    font-size: 28px;
    line-height: 44px;
  }
  .ulone li .li-left .li-footer span:nth-child(1){
    font-size: 24px;
    color: #558ef7;
  }
  .ulone li .li-left .li-footer span:nth-child(2){
    font-size: 22px;
    color: #8c8c8c;
    margin-left: 20px;
  }
  .ulone li img{
    width: 240px;
    height: 150px;
    border-radius: 10px;
  }
  .p1{
    padding: 20px 40px 30px 40px;
    font-size: 32px;
    border-top: 1px solid #ccc;
  }
  .ultwo{
    padding: 0 40px;
  }
  .ultwo li{
    position: relative;
    border-radius: 20px;
    background: #e7c7fd;
    margin-bottom: 30px;
    overflow: hidden;
  }
  .ultwo li .li-top{
    position: relative;
    height: 400px;
    overflow: hidden;
  }
  .ultwo li .li-top img{
    width: 100%;
    height: 100%;
  }
  .ultwo li .li-top span{
    position: absolute;
    left: 20px;
    top: 20px;
    display: inline-block;
    cursor: pointer;
  }
  .ultwo li .li-top span:nth-child(2){
    position: absolute;
    right: 20px;
    top: 20px;
    width: 90px;
    height: 40px;
    border-radius: 20px;
    text-align: center;
    line-height: 40px;
    background: #ff6174;
    color: #fff;
  }
  .ultwo li .li-top span:nth-child(3){
    width: 52px;
    height: 63px;
    background: url("/static/lyl/recom.png") no-repeat center/cover;
    font-size: 24px;
    color: #fff;
    float: right;
    text-align: center;
  }
  .ultwo li p{
    position: absolute;
    left: 0;
    bottom: 0;
    box-sizing: border-box;
    width: 100%;
    font-size: 24px;
    color: #fff;
    padding: 13px 0 10px 20px;
    background: rgba(0,0,0,0.7);
  }
</style>
